package com.nj.interfaces.login.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nj.framework.util.MD5;
import com.nj.interfaces.login.dao.UserDAO;

@Service
@Transactional
public class UserService {
	@Autowired
	private UserDAO userLoginDAO;

	// 简单登陆
	public Map<String, String> commonLogin(String userCode, String passWord) throws DataAccessException,
			ClassNotFoundException {
		Map<String, String> returnMap = new HashMap<String, String>();
		int count = userLoginDAO.queryUser(userCode, MD5.encode(passWord));
		if (count > 0) {
			// 用户名和密码正确
			// 给用户的信息放在里面
			returnMap = userLoginDAO.queryUserInfo(userCode);
			returnMap.put("flag", "Y");
		} else {
			returnMap.put("flag", "N");
			returnMap.put("errorMsg", "用户名或者密码不正确");
		}
		return returnMap;
	}

	// 简单登陆
	public Map<String, String> getUserInfo(String userCode) throws DataAccessException,
			ClassNotFoundException {
		Map<String, String> returnMap = new HashMap<String, String>();
		// 给用户的信息放在里面
		returnMap = userLoginDAO.queryUserInfo(userCode);
		returnMap.put("flag", "Y");
		return returnMap;
	}
	
	
	/** 
	 * 方法名：  getUserCondition 
	 * 描述：  获取用户奖惩列表
	 * @author  吴志虎   
	 * @param userCode
	 * @return
	 *
	 */
	public List<Map<String, Object>> getUserCondition (String userCode) {
		return userLoginDAO.getUserCondition(userCode);
	}
}
